from application import settings

# ================================================= #
# ***************** 插件配置区开始 *******************
# ================================================= #
# 路由配置
plugins_url_patterns = [
    {"re_path": r'api/uniapp/', "include": "dvadmin_uniapp.urls"},
]
# app 配置
apps = ['dvadmin_uniapp']
# 共享app配置(用于租户管理)
tenant_shared_apps = []
# 认证信息
authentication_backends = [{
    "name": "dvadmin_uniapp.backends.UniAppWxCodeBackend",
    "sort": 1
}, {
    "name": "dvadmin_uniapp.backends.UniAppPhoneCodeBackend",
    "sort": 2
}]
# ================================================= #
# ******************* 插件配置区结束 *****************
# ================================================= #

# ********** 添加登录认证 **********
_AUTHENTICATION_BACKENDS = list(getattr(settings, 'AUTHENTICATION_BACKENDS', []))
for ele in authentication_backends:
    _AUTHENTICATION_BACKENDS.insert(ele.get('sort'), ele.get('name'))
AUTHENTICATION_BACKENDS = sorted(list(set(_AUTHENTICATION_BACKENDS)), key=_AUTHENTICATION_BACKENDS.index)

# ********** 赋值到 settings 中 **********
settings.INSTALLED_APPS += [app for app in apps if app not in settings.INSTALLED_APPS]
settings.TENANT_SHARED_APPS += tenant_shared_apps

# ********** 注册路由 **********
settings.PLUGINS_URL_PATTERNS += plugins_url_patterns
